// ETS

package ca.etsmtl.log720.lab1;
import java.io.IOException;

import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;


public class ClientVoiture {

	public static void main(String[] args) {
		try {
			int x = 0;
			
			org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
			
			// Gestion du naming service
			NamingContextExt nc = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
			NameComponent[] name = null;
			
			//gestion de la  Banque Dossier
			name = new NameComponent[] { new NameComponent("BanqueDossiers", "service") };
			BanqueDossiers banqueDossiers = BanqueDossiersHelper.narrow(nc.resolve(name));
			
			//gestion de la banque de infraction
			name = new NameComponent[] { new NameComponent("Infractions", "service") };
			BanqueInfractions banqueInfractions = BanqueInfractionsHelper.narrow(nc.resolve(name));
					
			//get Banque Reactions
			name = new NameComponent[] { new NameComponent("Reactions", "service") };
			BanqueReactions banqueReactions = BanqueReactionsHelper.narrow(nc.resolve(name));
			System.out.println("Voulez-vous..");
			
			while (x != 3){
				System.out.println("Voulez-vous..");
				System.out.println("1: Consulter un dossier");
				System.out.println("2: Ajouter un dossier");
				System.out.println(": Quitter le systeme");
				
				
				if 	(x==1){
					//Section Recherche
					Dossier dossier = dossierLookup(banqueDossiers);
				}
				if (x==2) {
					//Section ajout au dossier
					while (x!=3){
						System.out.println("1: Ajouter un infraction a un dossier");
						System.out.println("2: Ajouter un reaction a un dossier");
						System.out.println("3: Retourner au menu precedant");
						
						if (x==1){
							Dossier dossier = dossierLookup(banqueDossiers);
							
						}
						if (x==2){
							Dossier dossier = dossierLookup(banqueDossiers);
							
						}
					}
					
				}
				
			}
			
			
				
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected static Dossier dossierLookup (BanqueDossiers banqueDossiers) throws IOException{
		int x = 0;
		Dossier dossier = null;
		
		while (x != 5) {
			System.out.println("Recherche par:");
			System.out.println("1: Numero de plaque");
			System.out.println("2: Nom:");
			System.out.println("3: Permis");
			System.out.println("4: ID");
			System.out.println("5: Menu precedente");
	
			x = System.in.read();
		}
		if (x == 1){
			System.out.println("Entrer le numero de plaque:");
			String plaque = System.in.toString();
			banqueDossiers.trouverDossiersParPlaque(plaque);
			//TODO: Trouver le dossier parmis la liste
			
			
		} else if (x==2){
			System.out.println("Entrer le nom: (format NomFamile, Prenom");
			String nom = System.in.toString();
		
		} else if (x==3) {
			System.out.println("Entrer le numero de permis:");
			String permis = System.in.toString();
			
		} else if (x==4){
			System.out.println("Entrer le numero d'idendification");
			String id = System.in.toString();
		
		}
		return dossier;
	}	
}
